Cache

class Cache<T>

JS/TS-friendly facade over com.sorinirmies.arrow.resiliencekit.Cache, specialized to string keys (the common case for JS/TS caches) to keep this facade's generics simple.

import { Cache } from "arrow-resilience-kit";

const cache = await Cache.create<User>({ maxSize: 1000, ttlMillis: 300_000 });
const user = await cache.getOrPut("user-123", () => userService.fetch("user-123"));

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Removes every entry.

Link copied to clipboard

Whether key is currently present (and not expired).

Link copied to clipboard
fun get(key: String): Promise<T?>

Gets the value for key, or undefined if absent/expired.

Link copied to clipboard
fun getOrPut(key: String, loader: () -> Promise<T>): Promise<T>

Gets the value for key, computing and storing it via loader if absent/expired.

Link copied to clipboard
fun put(key: String, value: T): Promise<Unit>

Puts value under key.

Link copied to clipboard
fun remove(key: String): Promise<T?>

Removes and returns the value for key, or undefined if it wasn't present.

Link copied to clipboard

Resets statistics counters (not the cache's contents).

Link copied to clipboard
fun size(): Promise<Int>

Current number of entries.

Link copied to clipboard

Current statistics snapshot.